Optional side-effect


In [6]:
val nameOpt = Option("Amir")

def printName(name: String) = println(name)


nameOpt: Option[String] = Some("Amir")
defined function printName

In [7]:
nameOpt.foreach(printName)


Amir



In [4]:
val anotherOpt = None


anotherOpt: None.type = None

In [5]:
anotherOpt.foreach(printName)



This is a great pattern for optinally generating side-effects given an option that you take from the command line, namely in conjunction with scallop.